﻿#ifndef __SNAKE_H__
#define __SNAKE_H__
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <windows.h>
#include <locale.h>
#include <stdbool.h>
#include <time.h>

#define FOOD (L"★")
#define WALL (L"□")
#define SELF (L"●")


#define POS_X (24)
#define POS_Y (5)

#define FOOD_X (((rand() % 27) + 1) * 2)
#define FOOD_Y ((rand() % 25) + 1)

#define GET_KEY(VK) ((GetAsyncKeyState(VK)&1)?1:0)

#define VK_Y (0x59)
#define VK_N (0x4E)


//枚举声明方向
typedef enum DIRECTION
{
	UP = 1,
	DOWN,
	LEFT,
	RIGHT
}DIRECTION;
//枚举声明状态
typedef enum GANE_STATE
{
	OK = 1,//正常运⾏
	KILL_BY_WALL,//撞墙
	KILL_BY_SELF,//咬到⾃⼰
	END_NORMAL//正常结束
}GANE_STATE;


//控制台的坐标类型
typedef short SnackCoord;
//控制台坐标
typedef struct Snakepos
{
	SnackCoord x;
	SnackCoord y;
}Snakepos;
//蛇身体的链表
typedef struct SnakeSList
{
	Snakepos data;
	struct SnakeSList* next;
}SnakeSList, * PSnakeSList;
//蛇的全部参数
typedef struct Snake
{
	PSnakeSList pSnake;//维护整条蛇的指针
	PSnakeSList pFood;//维护⻝物的指针
	DIRECTION dir;//蛇头的⽅向,默认是向右
	GANE_STATE state;//游戏状态
	int food_score; // 游戏当前获得分数
	int all_score;//默认每个⻝物10分
	int sleep_time;//每⾛⼀步休眠时间
}Snake, * PSnake;

//初始化游戏
void GameInit(PSnake snake);
//游戏运行
void GameRun(PSnake snake);
//结束游戏
void GameEnd(PSnake snake);
//定位光标位置
void SetCurPos(short x, short y);

#endif /*__SNAKE_H__*/


